﻿/*
-----------------------------------------------------------------------------
This source file is part of Cell Cloud.

Copyright (c) 2009-2012 Cell Cloud Team - cellcloudproject@gmail.com

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
-----------------------------------------------------------------------------
*/

#ifndef CellMessageHandler_h
#define CellMessageHandler_h

#include "CellPrerequisites.h"

namespace cell
{
/** \addtogroup Core
 *  @{
 */
/** \addtogroup General
 *  @{
 */

/** 消息服务处理监听器。
@author
	Jiangwei Xu
*/
class _CellExport MessageHandler
{
public:
	/** 默认构造函数。
	*/
	MessageHandler(void);

	/** 析构函数。
	*/
	virtual ~MessageHandler(void);

	/** 错误代码号。
	*/
	enum ErrorCode
	{
		/// 未知的错误类型。
		EC_UNKNOWN = 0,
		/// 无效的网络地址。
		EC_ADDRESS_INVALID,
		/// 错误的状态。
		EC_STATE_ERROR,
		/// Socket 函数发生错误。
		EC_SOCK_FAILED,
		/// 绑定服务时发生错误。
		EC_BIND_FAILED,
		/// 监听连接时发生错误。
		EC_LISTEN_FAILED,
		/// Accept 发生错误。
		EC_ACCEPT_FAILED,
		/// 写入数据时发生错误。
		EC_WRITE_FAILED,
		/// 连接超时
		EC_CONNECT_TIMEOUT
	};

public:
	/** 创建连接会话。
	*/
	virtual void sessionCreated(Session* session) = 0;

	/** 销毁连接会话。
	*/
	virtual void sessionDestroyed(Session* session) = 0;

	/** 开启连接会话。
	*/
	virtual void sessionOpened(Session* session) = 0;

	/** 关闭连接会话。
	*/
	virtual void sessionClosed(Session* session) = 0;

	/** 接收到消息。
	*/
	virtual void messageReceived(Session* session, Message* message) = 0;

	/** 消息已发送。
	*/
	virtual void messageSent(Session* session, Message* message) = 0;

	/** 发生错误。
	*/
	virtual void errorOccurred(uint16 errorCode, Session* session) = 0;
};

/** @} */
/** @} */
} // end namespace cell

#endif // CellMessageHandler_h
